package cn.yotta.user.web.autoconfiguration.utils;

import lombok.experimental.UtilityClass;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wyaoyao
 * @date 2022/11/8 14:53
 */
@UtilityClass
public class CookieUtils {

    public Map<String, String> readCookies(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        if (cookies == null || cookies.length == 0) {
            return null;
        }
        Map<String, String> cookieMap = new HashMap<>(16);

        for (Cookie cookie : cookies) {
            cookieMap.put(cookie.getName(), cookie.getValue());
        }

        return cookieMap;
    }
}
